package com.briup.jdbc;


import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.junit.Test;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;

/**
 * 读取properties文件
 * 使用连接池创建连接对象
 */
public class Test8 {
    Properties properties = new Properties();
    @Test
    public void testPropertiesOut(){
        InputStream in = Test8.class.getClassLoader().getResourceAsStream("com/briup/jdbc/db.properties");
        try {
            properties.load(in);
            System.out.println(properties);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    @Test
    public void testDruid(){
        // 加载数据
        testPropertiesOut();
        DataSource dataSource = null;
        try {
            dataSource =  DruidDataSourceFactory.createDataSource(properties);
            while (true) {
                Connection connection = dataSource.getConnection();
                System.out.println("connection = " + connection);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
